

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>节流</title>
</head>
<body>
    <button id="btn" style="margin: 200px; height: 100px; width: 200px;">提交</button>
</body>
<!-- <script src="../tools/lodash.js"></script> -->
<script>
    // btn.onclick = _.throttle(btnHandle, 10000, { 'trailing': false })
    // function btnHandle (e) {
    //     console.log(e)
    // }
    // 点击后开启一个计时器x，
    // 封锁住当前函数调用，
    // 当计时器完成后才重新开启
</script>
<script>
    function btnHandle (e) {
        console.log(e)
    }
    btn.onclick = throttle(btnHandle, 2000)
    function throttle (cb, t) {
        let block = false;
        let timer = null;
        return function () {
            if (!block) {
                cb.call(this, ...arguments);
                timer = setTimeout(() => {
                    clearTimeout(timer);
                    block = false;
                }, t);
                block = true;
            }
        }
    }
</script>


</html>